﻿using Coldairarrow.Business.PB;
using Coldairarrow.Business.TD;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_PickUpMainController : BaseApiController
    {
        #region DI

        public PB_PickUpMainController(IPB_PickUpMainBusiness pB_PickUpMainBus)
        {
            _pB_PickUpMainBus = pB_PickUpMainBus;
        }

        IPB_PickUpMainBusiness _pB_PickUpMainBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<PB_PickUpMain>> GetDataList(PageInput<List<ConditionDTO>> input)
        {
            return await _pB_PickUpMainBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<PB_PickUpMain> GetTheData(IdInputDTO input)
        {
            return await _pB_PickUpMainBus.GetTheDataAsync(input.id);
        }
        /// <summary>
        /// 打印备货单
        /// </summary>
        /// <param name="ParentId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<PB_PickUpMaininfo>> GetDataListInfo(string ParentId)
        {
            var res = await _pB_PickUpMainBus.GetDataListInfo(ParentId);
            return res;
        }
        /// <summary>
        /// 得到最新5条备货单信息
        /// </summary>
        /// <returns>5条备货单信息</returns>
        [HttpPost]
        public async Task<List<PB_PickUpMainDataListDTO>> GetPickUpMainDataList()
        {
            return await _pB_PickUpMainBus.GetPickUpMainDataList();
        }
        /// <summary>
        /// 装车验证
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_PickUpListTansportBillDTO> GetTranspotBillByPickUpListId(PageInput<ConditionDTO> input)
        {
            return await _pB_PickUpMainBus.GetTranspotBillByPickUpListId(input);
        }
        /// <summary>
        /// 打印装车单
        /// </summary>
        /// <param name="ParentId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_PickUpMainLoading> GetDataListLoadingInfo(string ParentId, string id)
        {
     return   await _pB_PickUpMainBus.GetDataListLoadingInfo(ParentId,id);

        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_PickUpMain data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_PickUpMainBus.AddDataAsync(data);
            }
            else
            {
                await _pB_PickUpMainBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_PickUpMainBus.DeleteDataAsync(ids);
        }

        /// <summary>
        /// 备货单新建获取步数
        /// </summary>
        /// <param name="NoticeItemId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<StepListDto>> GetStepListId(string NoticeItemId)
        {
            var list= await _pB_PickUpMainBus.GetStepListId(NoticeItemId);
            return list;
        }


        /// <summary>
        /// 原始保存步数及主表信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AjaxResult> AddStepsPickMain(AddStepsPickMain data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                return await _pB_PickUpMainBus.AddStepsPickMain(data);
            }
            else
            {
                return await _pB_PickUpMainBus.UpdateStepsPickMain(data);
            }
        }

        /// <summary>
        /// 替换物料保存
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
         [HttpPost]
        public async Task<AjaxResult> ReplacPickMain(AddStepsPickMain data) {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                return await _pB_PickUpMainBus.ReplaceAddPickMain(data);
            }
            else {
                return await _pB_PickUpMainBus.UpdateReplacePickMain(data);
            }
        }

        /// <summary>
        /// 备货效验
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async  Task<VerifyClose> TranslationStock(AddStepsPickMain data) {
            var list = await _pB_PickUpMainBus.TranslationStock(data);
            return list;
        }

        [HttpPost]
        public async Task<PageResult<InventoryDetail>> GetInventoryDetail(PageInput<RetrievalSeach> input)
        {
            return await _pB_PickUpMainBus.GetInventoryDetail(input);
        }
        #endregion
    }
}